package megajournal.DAO.query;

import megajournal.DAO.HibernateUtil;
import org.hibernate.Session;
import megajournal.domain.*;

/**
 *
 * @author cska
 * 
 */

public class Insert {

    private Session session;

    public Insert() {
        super();
    }

    private void begin() {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
    }

    private void commit() {
        session.getTransaction().commit();
    }

    public Group group(Group group) {
        begin();
        Group newGroup = (Group) session.merge(group);
        commit();

        return newGroup;
    }

    public Teacher teacher(Teacher teacher) {
        begin();
        Teacher newTeacher = (Teacher) session.merge(teacher);
        commit();

        return newTeacher;
    }

    public Subject subject(Subject subject) {
        begin();
        Subject newSubject = (Subject) session.merge(subject);
        commit();

        return newSubject;
    }

    public Student student(Student student) {
        begin();
        Student newStudent = (Student) session.merge(student);
        commit();

        return newStudent;
    }

    public Lesson lesson(Lesson lesson) {
        begin();
        Lesson newLesson = (Lesson) session.merge(lesson);
        commit();

        return newLesson;
    }

    public Skip skip(Skip skip) {
        begin();
        Skip newSkip = (Skip) session.merge(skip);
        commit();

        return newSkip;
    }

    public Group_Teacher_Subject gts(Group_Teacher_Subject gts) {
        begin();
        Group_Teacher_Subject newGts = (Group_Teacher_Subject) session.merge(gts);
        commit();

        return newGts;
    }

    public Lab lab(Lab lab) {
        begin();
        Lab newLab = (Lab) session.merge(lab);
        commit();

        return newLab;
    }

    public Lab_Student ls(Lab_Student ls) {
        begin();
        Lab_Student newLs = (Lab_Student) session.merge(ls);
        commit();

        return newLs;
    }

    public Interim interim(Interim interim) {
        begin();
        Interim newInterim = (Interim) session.merge(interim);
        commit();

        return newInterim;
    }

    public Admin admin(Admin admin) {
        begin();
        Admin newAdmin = (Admin) session.merge(admin);
        commit();

        return newAdmin;
    }

}
